# instructions for the macrosimualtion

## general information
The macrosimulation simulates a permanent and global 10% decrease in the skillpremium on the share of automation innovations in machinery (auto95/pauto95).

With the Skillpremium change, we run a direct prediction without recomputation of underlying stocks or spillovers, a version where firms patent stocks are recomputed after each year and a version where in addition to firms patent stocks, spillovers from a country's patent stock are recomputed yearly. We run a baseline with stovck and spillover recomputation, showing our underlying regression recreates the data well when no modification to the skillpremium is made. We take 1995 and 1996 as given and simulate all years from 1997 until 2011.

The run_simualtion.ps1 powershell calls different stata files in the batch directory, which in turn call the config and the main macrosimulation.do files. First, the powershell builds inputs, then it loops through through 4 batches of N runs each (where N is 200 in the paper, gibing us 800 runs) for all four scenarios described above. The looped processes are executed in parallel per loop iteration, to save time and take advantage of statas multithreading for up to 4 cores. As such, we advise a minimum of 12 cores for running this.

After the batches are run, batch_combine.do does as it suggests on the tin and combines the batches into larger files.
We output Figure 4 and table A43  with the rest of the tables and figures. The .tex for table A 43 unfortunately includes the Samsung year dummies, for the proper table please remove the superfluous lines.

## more details on different dofiles

### /batch directory 
-   XX_r_r_Y.do | files launch the simulation for the recompute stocks and spillover szenarios XX== 00 is no wagechange, XX== 01 is with wagechange. Y signifies the batchnumber
-   batch_keep_Y.do | launch all other versions of the simulation, wehre we do not recompute spillovers. Y signifies the batchnumber
-   batch combine.do | combines the different batches into larger files

#### main files
-   simulation config.do | sets paths and macros for the simulation irrespective of recalculation of spillovers and stocks
-   set globals.do |  sets macros and paths based on wehter we recumpute stocks, spillovers
-   build_inputs.do | acts as launcher to all different input constructing files
    -   build_BvD_year_div_data.do | reformats our regression data to the form we need it in the regression
    -   build_bvd_year_inventorcounts.do | counts patents by auto95, pauto95 per country and year, inputs for the distributing weights | only executed if patstat and orbis are present. | resulting files are included.
    -   build_weights_divnearest.do | takes the inventorcounts and constructs distributing weights by technology, including interpolation where no data is present.
    -   build_weights_pre.do | reformats the receiving spillover weights from the main analysis to fit the format of the simulation
    -   build_outsample_multiplier.do | builds a multiplier that multiplies any generated patents inside the simulation per country-year based on the fraction of real patents outside/inside the simulation.
    -   trunctuate_outsample_multiplier.do | trunctuates extreme multipliers generated by country-year combinations with very few patents
-   macro_simulation.do | the main flow of the simulation, does regression estimation and merging of preparatory data into one set. Calls all other executing files.
    -   helper.do | contains a program that distributes values from single cells to columns
    -   spillovers_init.do | loads the weights for spillovers and the multiplier
    -   predict_patenting.do | does the patent prediction, makes new stocks for the firms
    -   implement_stocks.do | reformats firm level stocks and does logs etc.
    -   recompute_spillovers.do | recomputes the countrystocks, multiplies with outsample multipliers and distributes them as spillovers to the firms
    -   implement_spillovers.do | implements logs and reformating for spillovers
    -   save_run.do | saves values generated that round
    -   destroy_spillovers.do | gets rid of unnecessary spillover variables carried through the run.